<?php
class FaceController extends NodeController {
	
	/**
	 * 头像上传入口
	 */
	public function index() {
		$message = $this->isLogin ();
		if ($message != self::SUCEESS) {
			$this->authorizeTemp ( $message );
			return;
		}
		
		$this->view ()->display ( "file:face/index.tpl" );
	}
	/**
	 * 头像审核列表
	 * Enter description here ...
	 */
	public function faceList() {
		$rs = self::getFaceService ()->getVaildFaceList ();
		$this->view ()->assign ( 'list', $rs );
		$this->view ()->display ( 'file:member/face.tpl' );
	}
	
	/**
	 * 生成申请队列
	 */
	public function resize() {
		$userinfo = self::getMemberService ()->getMemberByUid ( $this->_user_global ['uid'] );
		
		$rs = self::getFaceService ()->thumb ();
		
		if ($rs ['result_code'] != 1) {
			$message = self::ERROR;
		} else {
			$message = self::SUCEESS;
		}
		self::getFaceService ()->add ( $userinfo ['uid'], $rs ['result_des'] ['big'], $userinfo ['real_name'] );
		
		$this->sendNotice ( $message, $rs );
	}
	//审核通过，修改图片名称，防止覆盖掉
	public function vaild() {
		$rs = self::getFaceService ()->validFace ( $_POST ['id'], $_POST ['type'] );
		
		if ($rs != self::ERROR) {
			$info = self::getFaceService ()->getImageInfo ( getcwd () . $rs ['face'] );
			$newfile = dirname ( $rs ['face'] ) . '/' . $rs ['uid'] . '.' . $info ['type'];
			rename ( getcwd () . $rs ['face'], getcwd () . $newfile );
			$message = self::getMemberService ()->setMemberValue ( array ('face' => $newfile ), $rs ['uid'] );
			//删除成功的记录
			self::getFaceService ()->delFaceById ( $_POST ['id'] );
		
		}
		
		$this->sendNotice ( $message );
	}
	
	/**
	 * 上传头像原始大小
	 */
	public function setFace() {
		$rs = self::getFaceService ()->upload ( $_POST['uid'] );
		$this->sendNotice ( self::SUCEESS, $rs );
	}
	
	public static function getFaceService() {
		return new FaceService ();
	}

}